#!/bin/bash
#####################################
# Netkiller series tools
# Home: http://netkiller.sf.net
# Author: Neo Chen<openunix@163.com>
#####################################
SVNROOT=/srv/svnroot/zoshow
adduser(){
    if [ -z $1 ]; then
        usage
    else
        local user=$1
    fi
    if [ -z $2 ]; then
        passwd=$(cat /dev/urandom | tr -dc [:alnum:] | head -c 10)
    else
        local passwd=$2
    fi

    echo $user = $passwd
    echo "$user = $passwd" >> $SVNROOT/conf/passwd
}
deluser(){
    local user=$1
    if [ -z $user ]; then
        usage
    else
        ed -s $SVNROOT/conf/passwd <<EOF
/^$user = /
d
wq
EOF
    fi
}
list(){
    cat $SVNROOT/conf/passwd
}
usage(){
    echo $"Usage: $0 {list|add|del} username"
    exit 2
}
case "$1" in
    list)
        list
        ;;
    add)
        adduser $2 $3
        ;;
    del)
        deluser $2
        ;;
    restart)
        stop
        start
        ;;
    condrestart)
        condrestart
        ;;

    *)
        usage
        exit 1
esac

